module winapi.winsock2;

version (Windows)
{
	import std.c.windows.windows;
	import std.c.windows.winsock;
}
else
{
    static assert(0);		// Windows only
}

extern (Windows)
{
	alias HANDLE WSAEVENT;
	
	const int FD_MAX_EVENTS = 8;
	const int WSA_WAIT_TIMEOUT = 0x102;
	const int WSA_WAIT_FAILED = 0xFFFFFFFF;
	const int FIONREAD = 0x4004667F;
	
	enum 
	{
		FD_READ_BIT = 0,
		FD_WRITE_BIT = 1,
		FD_OOB_BIT = 2,
		FD_ACCEPT_BIT = 3,
		FD_CONNECT_BIT = 4,
		FD_CLOSE_BIT = 5
	}
	
	enum 
	{
		FD_READ         = 0x01,
		FD_WRITE        = 0x02,
		FD_OOB          = 0x04,
		FD_ACCEPT       = 0x08,
		FD_CONNECT      = 0x10,
		FD_CLOSE        = 0x20
	}
	struct WSANETWORKEVENTS {
		  int lNetworkEvents;
		  int[FD_MAX_EVENTS]  iErrorCode;
	}
	
	WSAEVENT WSACreateEvent();	
	int WSAEventSelect(
			  SOCKET s,
			  WSAEVENT hEventObject,
			  int lNetworkEvents
			);
	DWORD WSAWaitForMultipleEvents(
		DWORD cEvents,
		WSAEVENT *lphEvents,
		BOOL fWaitAll,
		DWORD dwTimeout,
		BOOL fAlertable
		);
	int WSAEnumNetworkEvents(
		SOCKET s,
		WSAEVENT hEventObject,
		WSANETWORKEVENTS *lpNetworkEvents
	);
}
